package org.electrical.controller.functionality;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.electrical.dao.EleOrderDetailsDao;
import org.electrical.pojo.EleOrderDetails;
import org.electrical.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/details")
@CrossOrigin(value = "*")
public class EleOrderDetailsController {

    @Autowired
    private EleOrderDetailsDao eleOrderDetailsDao;

    @RequestMapping("/list")
    @ResponseBody
    public ResponseResult<List<EleOrderDetails>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, int orderId) throws Exception {

        Page<EleOrderDetails> pager = PageHelper.startPage(page, limit);
        List<EleOrderDetails> list = eleOrderDetailsDao.getByOrderId(orderId);
        return new ResponseResult(pager.getTotal(), list);

    }

}
